package simple.tree;

import struct.TreeNode;

/**
 * <a href="https://leetcode-cn.com/problems/invert-binary-tree/">226. 翻转二叉树</a>
 * @author 刘学松
 * @date 2022-04-07 20:46
 */
public class 翻转二叉树 {
    public TreeNode invertTree(TreeNode root) {
        reverseTree(root);
        return root;
    }

    private void reverseTree(TreeNode node) {
        if (node != null) {
            TreeNode left = node.left;
            node.left = node.right;
            node.right = left;
            reverseTree(node.left);
            reverseTree(node.right);
        }
    }
}
